/*
 * general.cpp - general configure qcarpc widget
 *
 * Copyright (C) 2010-2011 Serge Begger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "general.h"
#include "ui_general.h"

general::general(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::general)
{
    ui->setupUi(this);
    settings = new QSettings("carpc", "general", this);
    settings->setPath(QSettings::IniFormat,QSettings::UserScope,"carpc");
    style_old = settings->value("style").toString();
    if (!style_old.size())
        style_old = QApplication::style()->objectName();
    QStringList supStyles = QStyleFactory::keys();
    if (supStyles.size())
    {
            int styleindex = supStyles.indexOf( QRegExp(style_old, Qt::CaseInsensitive, QRegExp::FixedString ) );
            ui->guistyle_comboBox->insertItems(0, supStyles);
            ui->guistyle_comboBox->setCurrentIndex( styleindex );
    }
    else
            ui->guistyle_comboBox->setEnabled( false );

}

void general::on_guistyle_comboBox_activated(QString style)
{
    QStyle *qstyle = NULL;
    if (style.size())
    {
        qstyle = QStyleFactory::create( style );
        if (qstyle)
            QApplication::setStyle( qstyle );
        settings->setValue("style",style);
    }

}

general::~general()
{
    delete ui;
}
